package com.example.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * Description:
 * User: 阿宾
 * Date: 2025-04-29
 * Time: 15:09
 */
@Slf4j  //用来打印日志
@Component //需要被Spring管理，加上五大注解之一
//@Aspect //表示当前类为切面类，用来处理某一类特定问题
@Order(3)
public class AspectDemo {

    @Pointcut("execution(* com.example.controller.*.*(..))")
    public void pt(){};
    //前置通知
    @Before("pt()")
    public void doBefore(){
        log.info("AspectDemo 执行 Before 方法");
    }
    //后置通知
    @After("pt()")
    public void doAfter(){
        log.info("AspectDemo 执行 After 方法");
    }
    /*//返回后通知
    @AfterReturning("pt()")
    public void doAfterReturning(){
        log.info("AspectDemo 执行 AfterReturning 方法");
    }

    //抛出异常后通知
    @AfterThrowing("execution(* com.example.controller.*.*(..))")
    public void doAfterThrowing(){
        log.info("AspectDemo 执行 AfterThrowing 方法");
    }
    //环绕通知
    @Around("execution(* com.example.controller.*.*(..))")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("AspectDemo Around 方法开始执行");
        Object result = joinPoint.proceed();
        log.info("AspectDemo Around 方法结束执行");
        return result;
    }*/

}
